package cn.bonoon.kernel.expression.results;

import cn.bonoon.kernel.events.ReadEvent;
import cn.bonoon.kernel.expression.ExpressionValue;
import cn.bonoon.kernel.expression.StandardExpressionParser;

public class UserExpressionValue implements ExpressionValue{
	private final String field, args;
	
	public UserExpressionValue(StandardExpressionParser seParser, String field, String args){
		this.field = field;
		this.args = args;
	}

	//id/owner[oi]/username[un]/displayname[dn]/isSuper[is]/isAdmin[ia]/now/get
	@Override
	public Object value(ReadEvent event, Object defaultValue) {
		switch (field) {
		case "id":
			return event.getId();
		case "owner":
		case "oi":
			return event.getOwnerId();
		case "username":
		case "un":
			return event.getUsername();
		case "displayname":
		case "dn":
			return event.getDisplayName();
		case "isSuper":
		case "is":
			return event.isSuper();
		case "isAdmin":
		case "ia":
			return event.isAdmin();
		case "now":
			return event.now();
		case "get":
			return event.get(args);
		}
		return defaultValue;
	}
}
